import 'package:flutter/material.dart';

class SliverAppBarSample extends StatefulWidget {
  const SliverAppBarSample({super.key});
  @override
  State<StatefulWidget> createState() {
    return SliverAppBarSampleState();
  }
}

class SliverAppBarSampleState extends State {
  bool _pinned = true;
  bool _snap = false;
  bool _floating = false;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: CustomScrollView(
        slivers: <Widget>[
          SliverAppBar(
            pinned: _pinned,
            snap: _snap,
            floating: _floating,
            expandedHeight: 160.0,
            flexibleSpace: const FlexibleSpaceBar(
              title: Text("SliverAppBar"),
              background: FlutterLogo(),
            ),
          ),
          const SliverToBoxAdapter(
            child: SizedBox(
              height: 20,
              child: Center(
                child: Text("Scroll to see the SliverAppBar in effect."),
              ),
            ),
          ),
          SliverList(
            delegate: SliverChildBuilderDelegate((context, index) {
              return Container(
                color: index.isOdd ? Colors.white : Colors.black12,
                height: 100.0,
                child: Center(
                  child: Text(
                    "$index",
                    textScaleFactor: 5,
                  ),
                ),
              );
            }, childCount: 20),
          )
        ],
      ),
      bottomNavigationBar: BottomAppBar(
          child: Padding(
        padding: const EdgeInsets.all(8),
        child: OverflowBar(
          overflowAlignment: OverflowBarAlignment.center,
          children: <Widget>[
            Row(
              mainAxisSize: MainAxisSize.min,
              children: <Widget>[
                const Text("pinned"),
                Switch(
                  value: _pinned,
                  onChanged: (value) {
                    setState(() {
                      _pinned = value;
                    });
                  },
                ),
              ],
            ),
            Row(
              mainAxisSize: MainAxisSize.min,
              children: <Widget>[
                const Text("snap"),
                Switch(
                  value: _snap,
                  onChanged: (value) {
                    setState(() {
                      _snap = value;
                      _floating = _floating || _snap;
                    });
                  },
                ),
              ],
            ),
            Row(
              mainAxisSize: MainAxisSize.min,
              children: <Widget>[
                const Text("floating"),
                Switch(
                  value: _floating,
                  onChanged: (value) {
                    setState(() {
                      _floating = value;
                      _snap = _snap && _floating;
                    });
                  },
                ),
              ],
            )
          ],
        ),
      )),
    );
  }
}
